export default {
	namespaced:true,
	
	// 数据
	state:()=>({
		address:JSON.parse(uni.getStorageSync('address') || '{}'),
		// 登录成功之后的token字符串
		token:uni.getStorageSync('token') || '{}',
		// 用户的基本信息
		userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'),
		// 重定向的object对象
		redirectInfo:null
	}),
	
	
	// 方法
	mutations:{
		// 更新收货地址
		updateAdress(state,address){
			state.address = address
			
			this.commit('my_user/saveAddressToStorage')
		},
		// 持久化存address
		saveAddressToStorage(state){
			uni.setStorageSync('address',JSON.stringify(state.address))
		},
		
		updateUserInfo(state,userinfo){
			state.userinfo = userinfo
			this.commit('my_user/saveUserInfoToStorage')
		},
		
		saveUserInfoToStorage(state){
			uni.setStorageSync('userinfo',JSON.stringify(state.userinfo))
		},
		
		updateToken(state,token){
			state.token = token
			this.commit('my_user/saveTokenToStorage')
		},
		
		saveTokenToStorage(state){
			uni.setStorageSync('token',state.token)
		},
		
		updateRedirectInfo(state,info){
			console.log(info)
			state.redirectInfo = info
		}
	},
	
	getters:{
		// 把地区合成为一个整体位置放在vuex里面 老几把方便了
		addstr(state){
			if(state.address.provinceName) return ''
			
			return state.address.provinceName + state.address.cityName + state.address.countryName + state.address.detailInfo
		}
	}
}